//
//  MyProfileViewController.m
//  League
//
//  Created by 博宇 李 on 2018/1/22.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "MyProfileViewController.h"
#import "TableViewCell.h"
#import "TYAttributedLabel.h"
#import "gkhPickerImage.h"
#import "FirstVcCollectionView.h"
#import "ImgCollectionViewCell.h"
#import "HYSlider.h"
#import "InterestsView.h"
#import "ChangeAlertView.h"
#import "PGGDropView.h"
#import "WaitForAuditViewController.h"
#import "AddInterestAlertView.h"
#import "CommonFunc.h"
#import "UserImageModel.h"
#import "MyPreferencesViewController.h"
#import "ProdileModel.h"
#import "PickerListViewController.h"
#import "ProfileManager.h"
#import "UserInfomation.h"
#import "MyProfileModel.h"

#define kTextFiledBgColor [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1]

#define kTextInfoColor [UIColor colorWithRed:190/255.0 green:190/255.0 blue:190/255.0 alpha:1]
#define kTitleFontSize 14
@interface MyProfileViewController ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,HYSliderDelegate,PGGDropDelegate, UITextFieldDelegate>
{
    NSInteger selectIndex;
    NSInteger segmentIndex;
    NSInteger saveAgeValue;
    
    NSInteger sexIndex;
    NSInteger saveSliderValue;
    NSInteger segmentlocaIndex;
    NSBundle *bundle ;
    
    NSString *cityNameLab;
    
    NSMutableArray *cityList ;
    
    
    NSInteger selectCityIndex;
    
    NSMutableArray *saveImageModelArr;
//    NSMutableArray *cityList;
}
@property(strong , nonatomic)UITableView *setupTableView;
@property(strong , nonatomic)UILabel *infoLab;
@property (nonatomic, strong) TYAttributedLabel *testLabel;
@property(strong,nonatomic)FirstVcCollectionView *imageCollecView;
@property(strong , nonatomic)NSMutableArray *imageArr;
@property(strong,nonatomic)UIAlertView *imgUpAlert;
@property(strong,nonatomic)UIAlertView *alert;
@property(strong , nonatomic)UITextField *aboutTf;
@property(strong , nonatomic)UITextField *userNameTf;
@property(strong , nonatomic)UITextField *emailTf;
@property(strong , nonatomic)InterestsView *interestsV;
@property(strong , nonatomic)InterestsView *worksV;
@property(strong , nonatomic)InterestsView *educationsV;
@property(strong , nonatomic)ChangeAlertView *changAlertV;
@property(strong,nonatomic)PGGDropView * dropView;
@property(strong , nonatomic) AddInterestAlertView *addInterestAlt;
@property (strong, nonatomic) ProdileModel *religion;
@property (strong, nonatomic) ProfileManager *maneger;
@end

@implementation MyProfileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.maneger = [ProfileManager shareManager];
    self.imageArr = [NSMutableArray array];
    cityList = [NSMutableArray array];
//    cityList = [NSMutableArray arrayWithObjects:@"城市一",@"城市二",@"城市三",@"城市四",@"城市五", nil];
    
    selectIndex = 0;
    segmentIndex = 0;
    sexIndex = 0;
    saveSliderValue = 150;
    saveAgeValue = 20;
    segmentlocaIndex = 0;
    selectCityIndex = 0;
    cityNameLab = @"";
//    for (int i= 0 ; i<6; i++) {
//        [self.imageArr addObject:@""];
//    }
    if (self.isRegister == YES) {
        NSLog(@"从注册页过来的");
    }
    else
    {
        NSLog(@"不是注册页");
        [self getUserInfoReqeust];
    }
    
    if (@available(iOS 11.0, *)) {
        self.setupTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    bundle = [InternationalControl bundle];
    self.title = [bundle localizedStringForKey:@"EditProfile" value:nil table:@"hello"];
    [self TableView];
    saveImageModelArr = [NSMutableArray array];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PickerValue:) name:kPickerNotifoStr object:nil];
    
    [self getCities];
    // Do any additional setup after loading the view.
}

- (void)getCities {
    NSDictionary *dic = @{
                          @"parentid":@(0),
                          @"typename":@"LocationCity"
                          };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kGetDictionary];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:dic requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            for (NSDictionary *city in backDic[@"obj"]) {
                ProdileModel *model = [[ProdileModel alloc] initWithDictionary:city error:nil];
                if (model != nil) {
                    [cityList addObject:model];
                }
            }
            [self.setupTableView reloadData];
        } else {
            
        }
    } requestFail:^(NSString *backErrorStr) {
        
        NSLog(@"backErrorStr:%@",backErrorStr);
        
    }];
}

- (void)getUserInfoReqeust {
    NSDictionary *dic = @{
                          @"pk1":[UserInfomation shareManager].pk
                          };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kProfileInfo];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:dic requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            MyProfileModel *model = [[MyProfileModel alloc] initWithDictionary:backDic[@"obj"] error:nil];
            self.maneger.sex = model.sex;
            if (model.userName != nil) {
                self.maneger.username = model.userName;
            }
            if (model.email != nil) {
                self.maneger.email = model.email;
            }
            self.maneger.age = model.age;
            [self.maneger.photoIds removeAllObjects];
            if (self.maneger.photoIds == nil) {
                self.maneger.photoIds = [NSMutableArray array];
            }
            if (self.imageArr == nil) {
                self.imageArr = [NSMutableArray array];
            }
            [self.imageArr removeAllObjects];
            for (CustomerPhotosModel *photoModel in model.customerPhotos) {
                if (photoModel._id != nil && photoModel.picUrl != nil) {
                    [self.maneger.photoIds addObject:photoModel._id];
                    UserImageModel *imageModel = [[UserImageModel alloc] init];
                    imageModel.picUrl = photoModel.picUrl;
                    imageModel.imageId = photoModel._id;
                    [self.imageArr addObject:imageModel];
                }
            }
            if (model.aboutme != nil) {
                self.maneger.aboutme = model.aboutme;
            }
            self.maneger.single = model.single;
            self.maneger.height = model.height;
            if (model.religionStr != nil) {
                self.religion._id = model.religion;
                self.religion.categoryName = model.religionStr;
                self.religion.categoryDesc = model.religionStr;
            }
            //职业
            [self.maneger.professionsArray removeAllObjects];
            if (self.maneger.professionsArray == nil) {
                self.maneger.professionsArray = [NSMutableArray array];
            }
            for (CustomerProfessionsModel *profrssionModel in model.customerProfessions) {
                if (profrssionModel._id != nil && profrssionModel.profession != nil) {
                    [self.maneger.professionsArray addObject:profrssionModel.profession];
                }
            }
            //教育
            [self.maneger.educationsArray removeAllObjects];
            if (self.maneger.educationsArray == nil) {
                self.maneger.educationsArray = [NSMutableArray array];
            }
            for (CustomerEducationsModel *educationsModel in model.customerEducations) {
                if (educationsModel._id != nil && educationsModel.education != nil) {
                    [self.maneger.educationsArray addObject:educationsModel.education];
                }
            }
            //兴趣
            [self.maneger.interestsArray removeAllObjects];
            if (self.maneger.interestsArray == nil) {
                self.maneger.educationsArray = [NSMutableArray array];
            }
            for (CustomerInterestsModel *inserstingModel in model.customerInterests) {
                if (inserstingModel._id != nil && inserstingModel.interest != nil) {
                    [self.maneger.interestsArray addObject:inserstingModel.interest];
                }
            }
            [self.setupTableView reloadData];
        } else {
            
        }
    } requestFail:^(NSString *backErrorStr) {
        
    }];
}

- (void)PickerValue:(NSNotification *)notification{
    if ([notification.userInfo[@"index"] intValue] == 9) {
        NSLog(@"从4回来");
        self.religion = notification.userInfo[@"data"];
    }
    [self.setupTableView reloadData];
}

-(void)TableView
{
    if (self.isRegister == NO) {
        self.setupTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 50)];//指定位置大小
    } else {
        self.setupTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 50)];//指定位置大小
    }

    [self.setupTableView setDelegate:self];//指定委托
    
    [self.setupTableView setDataSource:self];//指定数据委托
    self.setupTableView.estimatedRowHeight = 0;
    self.setupTableView.estimatedSectionHeaderHeight = 0;
    self.setupTableView.estimatedSectionFooterHeight = 0;
    self.setupTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.setupTableView];//加载tableview
    
    
//    [self.view addSubview:self.setupTableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return  14;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
//    if (!cell) {
//        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableViewCell"];
//        
//    }
//    static NSString *CellIdentifier = @"TableViewCell";
//         // 通过indexPath创建cell实例 每一个cell都是单独的
//         TableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//         // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
//         if (!cell) {
//                cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//             cell.selectionStyle = UITableViewCellSelectionStyleNone;
//             cell.width = tableView.width;
//            }
    
    static NSString *CellIdentifier = @"TableViewCell";
    // 通过indexPath创建cell实例 每一个cell都是单独的
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.width = tableView.width;
    }
    if(indexPath.row == 0)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Sex" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        NSArray *array = [NSArray arrayWithObjects:[bundle localizedStringForKey:@"Boy" value:nil table:@"hello"],[bundle localizedStringForKey:@"Girl" value:nil table:@"hello"], nil];
        //初始化UISegmentedControl
        UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
        //设置frame
        segment.frame = CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5);
        segment.center = CGPointMake(title.x+title.width+segment.width/2, kCellHeight/2);
        segment.selectedSegmentIndex = sexIndex;
        segment.tag = 202;
        //控件渲染色(也就是外观字体颜色)
        segment.tintColor = kAppColor;
        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
        //添加到视图
        [cell addSubview:segment];
        
    }
    else if (indexPath.row == 1)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"cinUserName" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        self.userNameTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, cell.width- title.width-10, kCellHeight/2)];
        self.userNameTf.center = CGPointMake(title.x+title.width+5+self.userNameTf.width/2, kCellHeight/2);
        self.userNameTf.backgroundColor = kTextFiledBgColor;
        if (self.maneger.username != nil) {
            self.userNameTf.text = self.maneger.username;
        }
        self.userNameTf.delegate = self;
        [cell addSubview:self.userNameTf];
    }
    else if (indexPath.row == 2)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Email" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        self.emailTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, cell.width- title.width-10, kCellHeight/2)];
        self.emailTf.center = CGPointMake(title.x+title.width+5+self.emailTf.width/2, kCellHeight/2);
        self.emailTf.backgroundColor = kTextFiledBgColor;
        if (self.maneger.email != nil) {
            self.emailTf.text = self.maneger.email;
        }
        self.emailTf.delegate = self;
        [cell addSubview:self.emailTf];
    }
    else if (indexPath.row == 3)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Age" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        HYSlider *slider1 = [[HYSlider alloc]initWithFrame:CGRectMake(title.x+title.width, 0, cell.width-title.width-20, kCellHeight/6)];
        slider1.center = CGPointMake(title.x+title.width+5+slider1.width/2, kCellHeight-slider1.height/2-5);
        slider1.currentValueColor = kAppColor;
        slider1.maxValue = 100;
        slider1.currentSliderValue = saveAgeValue;
        slider1.showTextColor = kAppColor;
        slider1.showTouchView = YES;
        slider1.showScrollTextView = YES;
        slider1.touchViewColor = kAppColor;
        slider1.delegate = self;
        slider1.tag = 200;
        [cell addSubview:slider1];
    
    }
    else if(indexPath.row == 4)
    {
        
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Photos" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        self.imageCollecView=[FirstVcCollectionView instance];
        self.imageCollecView.frame=CGRectMake(title.x+title.width, 0, cell.width- title.width-10, kPhotoCellHeight-20);
        self.imageCollecView.backgroundColor = [UIColor whiteColor];
        self.imageCollecView.dataSource=self;
        self.imageCollecView.delegate=self;
        self.imageCollecView.scrollEnabled = YES;
        [cell addSubview:self.imageCollecView];
        UILabel *bottomTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.imageCollecView.x, self.imageCollecView.y+self.imageCollecView.height, self.imageCollecView.width, 20)];
        bottomTitle.text =[bundle localizedStringForKey:@"Tap to replace,hold to reorder.6 pics required" value:nil table:@"hello"];
        bottomTitle.textColor = [UIColor colorWithRed:190/255.0 green:190/255.0 blue:190/255.0 alpha:1];
        bottomTitle.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:bottomTitle];
    }
    else if (indexPath.row == 5)
    {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"AboutMe" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        self.aboutTf = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, cell.width- title.width-10, kCellHeight/2)];
        self.aboutTf.center = CGPointMake(title.x+title.width+5+self.aboutTf.width/2, kCellHeight/2);
        self.aboutTf.backgroundColor = kTextFiledBgColor;
        if (self.maneger.aboutme != nil) {
            self.aboutTf.text = self.maneger.aboutme;
        }
        self.aboutTf.delegate = self;
        [cell addSubview:self.aboutTf];
    }
    else if (indexPath.row == 6) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Status" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        NSArray *array = [NSArray arrayWithObjects:[bundle localizedStringForKey:@"Single" value:nil table:@"hello"],[bundle localizedStringForKey:@"NotSingle" value:nil table:@"hello"], nil];
        //初始化UISegmentedControl
        UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
        //设置frame
        segment.frame = CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5);
        segment.center = CGPointMake(title.x+title.width+segment.width/2, kCellHeight/2);
        segment.selectedSegmentIndex = segmentIndex;
        segment.tag = 101;
        //控件渲染色(也就是外观字体颜色)
        segment.tintColor = kAppColor;
        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
        //添加到视图
        [cell addSubview:segment];
    }
    else if (indexPath.row == 7) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Height" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        HYSlider *slider1 = [[HYSlider alloc]initWithFrame:CGRectMake(title.x+title.width, 0, cell.width-title.width-20, kCellHeight/6)];
        slider1.center = CGPointMake(title.x+title.width+5+slider1.width/2, kCellHeight-slider1.height/2-5);
        slider1.currentValueColor = kAppColor;
        slider1.maxValue = 200;
        slider1.currentSliderValue = saveSliderValue;
        slider1.showTextColor = kAppColor;
        slider1.showTouchView = YES;
        slider1.showScrollTextView = YES;
        slider1.touchViewColor = kAppColor;
        slider1.delegate = self;
        slider1.tag = 1000;
        [cell addSubview:slider1];
    }
    /*
    else if (indexPath.row == 8) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Ethnicity" value:nil table:@"hello"];
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        [cell addSubview:title];
        UIButton *cityTextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        cityTextBtn.center = CGPointMake(title.x+title.width+cityTextBtn.width/2, kCellHeight/2);
        cityTextBtn.backgroundColor = kTextFiledBgColor;
        [cityTextBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        cityTextBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cityTextBtn setTitle:@"Asian" forState:UIControlStateNormal];
        [cell addSubview:cityTextBtn];
    }
    */
    else if (indexPath.row == 8) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Distance" value:nil table:@"hello"];
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        [cell addSubview:title];
        
        UILabel *infoLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        infoLab.center = CGPointMake(title.x+title.width+infoLab.width/2, kCellHeight/2);
//        infoLab.text = cityList[selectCityIndex];
        if (cityList.count != 0) {
            ProdileModel *model = cityList[selectCityIndex];
            NSString *lan = [InternationalControl userLanguage];
            if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
                infoLab.text = model.categoryDesc;
            } else {
                infoLab.text = model.categoryName;
            }
        } else {
            infoLab.text = [bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"];
        }
        infoLab.textAlignment = NSTextAlignmentCenter;
        infoLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:infoLab];
//        NSArray *array = [NSArray arrayWithObjects:@"城市1",@"城市2",@"城市3", nil];
//        //初始化UISegmentedControl
//        UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
//        //设置frame
//        segment.frame = CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5);
//        segment.center = CGPointMake(title.x+title.width+segment.width/2, kCellHeight/2);
//        segment.selectedSegmentIndex = segmentlocaIndex;
//        segment.tag = 103;
//        //控件渲染色(也就是外观字体颜色)
//        segment.tintColor = kAppColor;
//        [segment addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
//        //添加到视图
//        [cell addSubview:segment];
    }
    else if (indexPath.row == 9) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Religion" value:nil table:@"hello"];
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        [cell addSubview:title];
        UIButton *religionBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width-title.width-10, kCellHeight*0.5)];
        religionBtn.center = CGPointMake(title.x+title.width+religionBtn.width/2, kCellHeight/2);
        religionBtn.backgroundColor = kTextFiledBgColor;
        [religionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        religionBtn.titleLabel.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        if (self.religion == nil) {
            [religionBtn setTitle:[bundle localizedStringForKey:@"NoPreference" value:nil table:@"hello"] forState:UIControlStateNormal];
        } else {
            NSString *lan = [InternationalControl userLanguage];
            if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
                [religionBtn setTitle:self.religion.categoryDesc forState:UIControlStateNormal];
            } else {
                [religionBtn setTitle:self.religion.categoryName forState:UIControlStateNormal];
            }
        }
        
        religionBtn.userInteractionEnabled = NO;
        [cell addSubview:religionBtn];
    }
    else if (indexPath.row == 10) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Profession" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        
        /*
        UIButton *headButton = [[UIButton alloc] initWithFrame:CGRectMake(title.x+title.width, kheightSpace, cell.width-title.width-10, kProfessionHeight)];
        [headButton addTarget:self action:@selector(touch:) forControlEvents:UIControlEventTouchDown];
        headButton.backgroundColor = kTextFiledBgColor;
        [headButton setTitle:@"xxxxxxxxxxxxx" forState:UIControlStateNormal];
        [headButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        headButton.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [headButton addTarget:self action:@selector(ProfessionHeadButton:) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:headButton];
        
        UILabel *infoLab = [[UILabel alloc] initWithFrame:CGRectMake(headButton.x, headButton.y+headButton.height, headButton.width, kinfoLabHeight)];
        infoLab.textColor = kTextInfoColor;
        infoLab.text = [bundle localizedStringForKey:@"Former jobs visible post-match only" value:nil table:@"hello"];
        infoLab.adjustsFontSizeToFitWidth = YES;
        infoLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:infoLab];
         */
        
        for (int i = 0; i<self.maneger.professionsArray.count; i++) {
            /*
            UIButton *schoolInfoBtn = [[UIButton alloc ] initWithFrame:CGRectMake(headButton.x, infoLab.y+infoLab.height+i*kProfessionHeight+kheightSpace*i, cell.width-title.width-10, kProfessionHeight)];
            headButton.tag = i;
            schoolInfoBtn.backgroundColor = kTextFiledBgColor;
            [schoolInfoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [schoolInfoBtn setTitle:@"xxxxxxxxxxxxx" forState:UIControlStateNormal];
            schoolInfoBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
            [schoolInfoBtn addTarget:self action:@selector(ProfessionChangeButton:) forControlEvents:UIControlEventTouchDown];
            [cell addSubview:schoolInfoBtn];
             */
            self.worksV = [[InterestsView alloc ] initWithFrame:CGRectMake(title.x+title.width, title.y+i*kProfessionHeight+kheightSpace, cell.width-title.width, kProfessionHeight)];
            self.worksV.tag = i;
            self.worksV.delBtn.tag = i;
            //            self.interestsV.backgroundColor = [UIColor lightGrayColor];
            self.worksV.interestLab.text = self.maneger.professionsArray[i];
            [self.worksV.delBtn addTarget:self action:@selector(worksBtn:) forControlEvents:UIControlEventTouchDown];
            self.worksV.interestLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
            [cell addSubview:self.worksV];
        }
        
        UIButton *addBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width/3, kAddBtnheight)];
        addBtn.center = CGPointMake(cell.width/2, kProfessionHeight*(self.maneger.professionsArray.count + 1)+kheightSpace+kAddBtnheight - addBtn.height/2);
        addBtn.backgroundColor = kAppColor;
        addBtn.tag = 300 + indexPath.row;
        [addBtn setTitle:[bundle localizedStringForKey:@"AddWork" value:nil table:@"hello"] forState:UIControlStateNormal];
        addBtn.layer.masksToBounds = YES;
        addBtn.layer.cornerRadius = 8;
        addBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
        addBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [addBtn addTarget:self action:@selector(addInster:) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:addBtn];
    }
   else if (indexPath.row == 11) {
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Education" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
       title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        for (int i = 0; i<self.maneger.educationsArray.count; i++) {
            self.educationsV = [[InterestsView alloc ] initWithFrame:CGRectMake(title.x+title.width, title.y+i*kProfessionHeight+kheightSpace, cell.width-title.width, kProfessionHeight)];
            self.educationsV.tag = i;
            self.educationsV.delBtn.tag = i;
            //            self.interestsV.backgroundColor = [UIColor lightGrayColor];
            self.educationsV.interestLab.text = self.maneger.educationsArray[i];
            [self.educationsV.delBtn addTarget:self action:@selector(educationsBtn:) forControlEvents:UIControlEventTouchDown];
            self.educationsV.interestLab.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
            [cell addSubview:self.educationsV];
        }
       
       UIButton *addBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width/3, kAddBtnheight)];
       addBtn.center = CGPointMake(cell.width/2, kProfessionHeight*(self.maneger.educationsArray.count +1)+kheightSpace+kAddBtnheight-addBtn.height/2);
       addBtn.backgroundColor = kAppColor;
       [addBtn setTitle:[bundle localizedStringForKey:@"AddEducation" value:nil table:@"hello"] forState:UIControlStateNormal];
       addBtn.tag = 300 + indexPath.row;
       addBtn.layer.masksToBounds = YES;
       addBtn.layer.cornerRadius = 8;
       addBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
       addBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
       [addBtn addTarget:self action:@selector(addInster:) forControlEvents:UIControlEventTouchDown];
       [cell addSubview:addBtn];
    }
    else if (indexPath.row == 12){
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/3.5, kCellHeight)];
        title.text = [bundle localizedStringForKey:@"Interests" value:nil table:@"hello"];
        title.textAlignment = NSTextAlignmentCenter;
        title.adjustsFontSizeToFitWidth = YES;
        title.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:title];
        for (int i = 0; i<self.maneger.interestsArray.count; i++) {
            self.interestsV = [[InterestsView alloc ] initWithFrame:CGRectMake(title.x+title.width, title.y+i*kProfessionHeight+kheightSpace, cell.width-title.width, kProfessionHeight)];
            self.interestsV.tag = i;
            self.interestsV.delBtn.tag = i;
//            self.interestsV.backgroundColor = [UIColor lightGrayColor];
            self.interestsV.interestLab.text = self.maneger.interestsArray[i];
            [self.interestsV.delBtn addTarget:self action:@selector(delBtn:) forControlEvents:UIControlEventTouchDown];
            self.interestsV.interestLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
            [cell addSubview:self.interestsV];
        }
        UIButton *addBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width/3, kAddBtnheight)];
        addBtn.center = CGPointMake(cell.width/2, kProfessionHeight*(self.maneger.interestsArray.count + 1)+kheightSpace+kAddBtnheight-addBtn.height/2);
        addBtn.backgroundColor = kAppColor;
        [addBtn setTitle:[bundle localizedStringForKey:@"AddInterest" value:nil table:@"hello"] forState:UIControlStateNormal];
        addBtn.tag = 300 + indexPath.row;
        addBtn.layer.masksToBounds = YES;
        addBtn.layer.cornerRadius = 8;
        addBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
        addBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [addBtn addTarget:self action:@selector(addInster:) forControlEvents:UIControlEventTouchDown];
        [cell addSubview:addBtn];
    }
    else if (indexPath.row == 13){
        UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, cell.width/2.5, kCellHeight/2)];
        nextBtn.center = CGPointMake(cell.width/2, kCellHeight/2);
        nextBtn.backgroundColor = kAppColor;
        nextBtn.layer.masksToBounds = YES;
        nextBtn.layer.cornerRadius = 8;
        nextBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
        [nextBtn addTarget:self action:@selector(nextBtn:) forControlEvents:UIControlEventTouchDown];
        nextBtn.titleLabel.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        [cell addSubview:nextBtn];
        if (self.isRegister == YES) {
            [nextBtn setTitle:[bundle localizedStringForKey:@"Next" value:nil table:@"hello"] forState:UIControlStateNormal];
        } else {
            [nextBtn setTitle:[bundle localizedStringForKey:@"over" value:nil table:@"hello"] forState:UIControlStateNormal];
        }
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"row:%@ - section:%@",@(indexPath.row) , @(indexPath.section));
    if (indexPath.row == 8)
    {
        [self.dropView removeFromSuperview];
        NSString *lan = [InternationalControl userLanguage];
        NSMutableArray *titleArray = [NSMutableArray array];
        if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
            for (ProdileModel *model in cityList) {
                [titleArray addObject:model.categoryDesc];
            }
        } else {
            for (ProdileModel *model in cityList) {
                [titleArray addObject:model.categoryName];
            }
        }
        self.dropView = [[PGGDropView alloc] initWithFrame:CGRectMake(0, 0 ,self.view.width, 300) withTitleArray:titleArray];
        self.dropView.center = CGPointMake(self.view.width/2, self.view.height/2);
        self.dropView.backgroundColor = kTextFiledBgColor;
        [self.dropView beginAnimation];
        self.dropView.delegate = self;
        [self.view addSubview:self.dropView];
    }
    if (indexPath.row == 9) {
        PickerListViewController *pickerVc = [[PickerListViewController alloc] init];
        pickerVc.isRadio = YES;
        pickerVc.index = indexPath.row;
        pickerVc.type = Religion;
        [self presentViewController:pickerVc animated:YES completion:nil];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 4) {
        return kPhotoCellHeight;
    }
   else if (indexPath.row == 10) {
        return kProfessionHeight*(self.maneger.professionsArray.count +1) +kheightSpace+kAddBtnheight;
    }
    else if (indexPath.row == 11) {
       return kProfessionHeight* (self.maneger.educationsArray.count +1) + kheightSpace+kAddBtnheight;
    }
    else if (indexPath.row == 12){
        return kProfessionHeight*(self.maneger.interestsArray.count + 1)+kheightSpace+kAddBtnheight;
    }
    else
    {
       return kCellHeight;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 0;
    
}

- (void)PGGDropView:(PGGDropView *)DropView didSelectAtIndex:(NSInteger )index{
    
    NSLog(@"%ld",index);
    NSInteger ind = index - 100;
    
    selectCityIndex = ind;
    //    cityNameLab = cityList[ind];
    [self.setupTableView reloadData];
}
//collectionView delegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 6;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *reuseIdentifier = @"ImgCollectionViewCell";
    UINib *nib = [UINib nibWithNibName:@"ImgCollectionViewCell" bundle: [NSBundle mainBundle]];
    [collectionView registerNib:nib forCellWithReuseIdentifier:reuseIdentifier];
    ImgCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.backgroundColor=[UIColor whiteColor];
    cell.typeLab.frame=CGRectMake(0, 0, 0, 0);
    cell.imgView.frame = CGRectMake(0, 0, cell.height*0.4, cell.height*0.4);
    cell.imgView.image = [UIImage imageNamed:@"add"];
    /*
    if ([self.imageArr[indexPath.row] isKindOfClass:[UIImage class]]) {
//        cell.imgView.image=[UIImage imageNamed:self.imageArr[indexPath.row]];
//        if (indexPath.row==self.imageArr.count-1) {
        cell.imgView.frame = CGRectMake(0, 0, cell.height*0.4, cell.height*0.4);
        cell.imgView.image = [UIImage imageNamed:@"add"];
//        }
    }
    else if ([self.imageArr[indexPath.row] isKindOfClass:[UIImage class]])
    {
        cell.imgView.frame=CGRectMake(0, 0, cell.height*0.9, cell.height*0.9);
        cell.imgView.image=self.imageArr [indexPath.row];
    }
    else
    {
        cell.imgView.frame = CGRectMake(0, 0, cell.height*0.4, cell.height*0.4);
        cell.imgView.image = [UIImage imageNamed:@"add"];
        NSLog(@"%@:????????",@(indexPath.row));
    }
    */
    cell.imgView.center = CGPointMake(cell.width/2, cell.height/2);
    
    if (indexPath.row < self.imageArr.count && self.imageArr.count != 0) {
        UserImageModel *model = self.imageArr[indexPath.row];
        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"add"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            //改变 + 大小
            if ([cell.imgView.image isEqual:[UIImage imageNamed:@"add"]]) {
                cell.imgView.frame = CGRectMake(0, 0, cell.height*0.4, cell.height*0.4);
                cell.imgView.center = CGPointMake(cell.width/2, cell.height/2);
            } else {
                cell.imgView.frame = CGRectMake(0, 0, cell.height*0.8, cell.height*0.8);
                cell.imgView.center = CGPointMake(cell.width/2, cell.height/2);
            }
        }];
    }
    

    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(collectionView.width/3-1, collectionView.height/2-1);
    
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

// 两行之间的最小间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 0;
    
}

// 两个cell之间的最小间距，是由API自动计算的，只有当间距小于该值时，cell会进行换行
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    selectIndex = indexPath.row;
    if (indexPath.row<self.imageArr.count) {
        [gkhPickerImage sharePictureByController:self susscond:^(UIImage *image, UIViewController *controller) {
            [self postImage:image :@"0" :@""];
        }];
    } else {
        [gkhPickerImage sharePictureByController:self susscond:^(UIImage *image, UIViewController *controller) {
            [self postImage:image :@"1":@""];
        }];
    }
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if ([textField isEqual:self.aboutTf]) {
        self.maneger.aboutme = textField.text;
    }
    if ([textField isEqual:self.userNameTf]) {
        self.maneger.username = textField.text;
    }
    if ([textField isEqual:self.emailTf]) {
        self.maneger.email = textField.text;
    }
}

-(void)postImage:(UIImage *)image :(NSString *)type :(NSString *)name
{
    NSLog(@"正在上传图片");
    NSLog(@"照片名:%@",name);
    NSString *msg=[NSString stringWithFormat:@"%@上传中...",name];
    self.imgUpAlert=[[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [self.imgUpAlert show];

    NSString *a = [NSString stringWithFormat:@"%@%@",kFirstUrl,kUpImageUrl];
    NSDictionary *params;
    if (self.isRegister == NO) {
        if (selectIndex < self.imageArr.count) {
            UserImageModel *model = self.imageArr[selectIndex];
            params = @{@"customerId":[UserInfomation shareManager].pk,@"sortOrder":[NSString stringWithFormat:@"%@",@(selectIndex)],@"pk":model.imageId};
        } else {
            params = @{@"customerId":[UserInfomation shareManager].pk,@"sortOrder":[NSString stringWithFormat:@"%@",@(selectIndex)],@"pk":@"0"};
        }
    } else {
       params = @{@"customerId":@"0",@"sortOrder":[NSString stringWithFormat:@"%@",@(selectIndex)],@"pk":@"0"};
    }
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:a parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSData *data = UIImagePNGRepresentation(image);
        NSString *fileName = @"12312312.jpg";
        [formData appendPartWithFileData:data name:@"myfile" fileName:fileName mimeType:@"image/png"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"%f",1.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
        dispatch_async(dispatch_get_main_queue(), ^{
//            if (ProgresBackBlock) {
//                ProgresBackBlock(1.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
//            }
        });
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"responseObject:%@",responseObject);
        [self.imgUpAlert dismissWithClickedButtonIndex:0 animated:NO];
        
        UserImageModel *model = [[UserImageModel alloc] init];
        model.imageId = responseObject[@"obj"][@"pk"];
        model.picUrl = responseObject[@"obj"][@"url"];
        if ([type isEqualToString:@"0"]) {
            [self.imageArr replaceObjectAtIndex:selectIndex withObject:model];
        } else {
            [self.imageArr addObject:model];
        }
        
        [self.setupTableView reloadData];
//        //上传成功
//        if (uploadSuccessBackBlock) {
//            uploadSuccessBackBlock(responseObject);
//        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",[error localizedDescription]);
        [self.imgUpAlert dismissWithClickedButtonIndex:0 animated:NO];
        //上传失败
//        if (uploadFailBackBlock) {
//            uploadFailBackBlock([error localizedDescription]);
//        }
    }];
  
}

-(void)change:(UISegmentedControl *)sender{
    
    if (sender.tag == 101) {
        segmentIndex = sender.selectedSegmentIndex;
    }
    else if (sender.tag == 202)
    {
        sexIndex = sender.selectedSegmentIndex;
    }
    else
    {
        segmentlocaIndex = sender.selectedSegmentIndex;
    }
  
}
-(void)alert:(NSString *)alertStr
{
    self.alert=[[UIAlertView alloc]initWithTitle:[bundle localizedStringForKey:@"Prompt" value:nil table:@"hello"] message:alertStr delegate:nil cancelButtonTitle:[bundle localizedStringForKey:@"ok" value:nil table:@"hello"] otherButtonTitles: nil];
    [self.alert show];
    [self performSelector:@selector(missAlert) withObject:nil afterDelay:1.5];
    
}
-(void)touch:(UIButton *)btn
{
    
}

- (void)worksBtn:(UIButton *)sender {
    [self.maneger.professionsArray removeObjectAtIndex:sender.tag];
    [self.setupTableView reloadData];
}

-(void)delBtn:(UIButton *)btn
{
    NSLog(@"%@",@(btn.tag));
    [self.maneger.interestsArray removeObjectAtIndex:btn.tag];
    [self.setupTableView reloadData];
}

- (void)educationsBtn:(UIButton *)sender {
    [self.maneger.educationsArray removeObjectAtIndex:sender.tag];
    [self.setupTableView reloadData];
}

-(void)missAlert
{
    
    [self.alert dismissWithClickedButtonIndex:0 animated:NO];
    
}
- (void)HYSlider:(HYSlider *)hySlider didScrollValue:(CGFloat)value{
    
    NSLog(@"%f",value);
    if (hySlider.tag == 1000) {
        saveSliderValue = value;
    }
    else
    {
        saveAgeValue = value;
    }
    
}
-(void)nextBtn:(UIButton *)btn
{
    
    self.maneger.sex = sexIndex;
    self.maneger.realname = self.userNameTf.text;
    self.maneger.email = self.emailTf.text;
    self.maneger.age = saveAgeValue;
    if (self.maneger.photoIds == nil) {
        self.maneger.photoIds = [NSMutableArray array];
    }
    [self.maneger.photoIds removeAllObjects];
    if (self.imageArr.count > 0) {
        for (UserImageModel *model in self.imageArr) {
            [self.maneger.photoIds addObject:model.imageId];
        }
    }
    self.maneger.aboutme = self.aboutTf.text;
    if (segmentIndex == 0) {
        self.maneger.single = true;
    } else {
        self.maneger.single = false;
    }
    self.maneger.height = saveSliderValue;
    if (cityList.count > 0) {
        ProdileModel *model = cityList[selectCityIndex];
        if (model._id != nil) {
            self.maneger.location = model._id;
        }
    }
    if (self.religion._id != nil) {
        self.maneger.religion = self.religion._id;
    }

    if (self.isRegister == NO) {
        [self editProfileRequest];
        return;
    }
    
    MyPreferencesViewController *myPreferencesVc = [[MyPreferencesViewController alloc] init];
    myPreferencesVc.isRegister = YES;
    [self.navigationController pushViewController:myPreferencesVc animated:YES];

//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[bundle localizedStringForKey:@"Prompt" value:nil table:@"hello"] message:[bundle localizedStringForKey:@"wait" value:nil table:@"hello"] delegate:self cancelButtonTitle:[bundle localizedStringForKey:@"ok" value:nil table:@"hello"] otherButtonTitles:nil, nil];
//    [alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)editEducation:(UIButton *)btn
{
    NSLog(@"%@",@(btn.tag));
    [self.changAlertV removeFromSuperview];
    self.changAlertV = [[ChangeAlertView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
   [[UIApplication sharedApplication].keyWindow addSubview:self.changAlertV];
    
    self.changAlertV.headLab.text = [bundle localizedStringForKey:@"CHANGE EDUCATION" value:nil table:@"hello"];
    
    [self.changAlertV.changeBtn setTitle:[bundle localizedStringForKey:@"change" value:nil table:@"hello"] forState:UIControlStateNormal];
    [self.changAlertV.cancelBtn setTitle:[bundle localizedStringForKey:@"cancel" value:nil table:@"hello"] forState:UIControlStateNormal];
}

-(void)ProfessionHeadButton:(UIButton *)btn
{
    [self.changAlertV removeFromSuperview];
    self.changAlertV = [[ChangeAlertView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [[UIApplication sharedApplication].keyWindow addSubview:self.changAlertV];
    
    self.changAlertV.headLab.text = [bundle localizedStringForKey:@"CHANGE PROFESSION" value:nil table:@"hello"];
    
    [self.changAlertV.changeBtn setTitle:[bundle localizedStringForKey:@"change" value:nil table:@"hello"] forState:UIControlStateNormal];
    [self.changAlertV.cancelBtn setTitle:[bundle localizedStringForKey:@"cancel" value:nil table:@"hello"] forState:UIControlStateNormal];
}
-(void)ProfessionChangeButton:(UIButton *)btn
{
    [self.changAlertV removeFromSuperview];
    self.changAlertV = [[ChangeAlertView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [[UIApplication sharedApplication].keyWindow addSubview:self.changAlertV];
    
    self.changAlertV.headLab.text = [bundle localizedStringForKey:@"CHANGE PROFESSION" value:nil table:@"hello"];
    
    [self.changAlertV.changeBtn setTitle:[bundle localizedStringForKey:@"change" value:nil table:@"hello"] forState:UIControlStateNormal];
    [self.changAlertV.cancelBtn setTitle:[bundle localizedStringForKey:@"cancel" value:nil table:@"hello"] forState:UIControlStateNormal];
}
-(void)addInster:(UIButton *)sender
{
    NSInteger index = sender.tag - 300;
    [self.addInterestAlt removeFromSuperview];
    self.addInterestAlt = [[AddInterestAlertView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [[UIApplication sharedApplication].keyWindow addSubview:self.addInterestAlt];
    
    if (index == 10) {
        self.addInterestAlt.headLab.text = [bundle localizedStringForKey:@"AddWork" value:nil table:@"hello"];
    } else if (index == 11) {
        self.addInterestAlt.headLab.text = [bundle localizedStringForKey:@"AddEducation" value:nil table:@"hello"];
    } else {
        self.addInterestAlt.headLab.text = [bundle localizedStringForKey:@"addinterest" value:nil table:@"hello"];
    }
    [self.addInterestAlt.addBtn setTitle:[bundle localizedStringForKey:@"Add" value:nil table:@"hello"] forState:UIControlStateNormal];
    [self.addInterestAlt.addBtn addTarget:self action:@selector(AddAction:) forControlEvents:UIControlEventTouchUpInside];
    self.addInterestAlt.addBtn.tag = 400 + index;
    [self.addInterestAlt.cancelBtn setTitle:[bundle localizedStringForKey:@"cancel" value:nil table:@"hello"] forState:UIControlStateNormal];
}

- (void)AddAction:(UIButton *)sender {
    [self.addInterestAlt removeFromSuperview];
    
    NSInteger index = sender.tag - 400;
    if (index == 10) {
        if (self.maneger.professionsArray == nil) {
            self.maneger.professionsArray = [NSMutableArray array];
        }
        [self.maneger.professionsArray addObject:self.addInterestAlt.textFileOne.text];
    } else if (index == 11) {
        if (self.maneger.educationsArray == nil) {
            self.maneger.educationsArray = [NSMutableArray array];
        }
        [self.maneger.educationsArray addObject:self.addInterestAlt.textFileOne.text];
    } else {
        if (self.maneger.interestsArray == nil) {
            self.maneger.interestsArray = [NSMutableArray array];
        }
        [self.maneger.interestsArray addObject:self.addInterestAlt.textFileOne.text];
    }
    [self.setupTableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)editProfileRequest {
    if (self.maneger.photoIds.count == 0) {
        [self showAlert:@"请至少上传一张照片"];
        return;
    }
    [self refreshBegin];
    NSDictionary *parameters = [self setParameters];
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kEditProfileInfo];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        [self refreshStop];
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
        
    }];
}

- (NSDictionary *)setParameters {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[UserInfomation shareManager].pk forKey:@"pk"];
    [parameters setObject:@(self.maneger.sex) forKey:@"sex"];
    if (self.maneger.username != nil) {
        [parameters setObject:self.maneger.username forKey:@"username"];
        [parameters setObject:self.maneger.realname forKey:@"realname"];
    }
    if (self.maneger.email != nil) {
        [parameters setObject:self.maneger.email forKey:@"email"];
    }
    [parameters setObject:@(self.maneger.age) forKey:@"age"];
    if (self.maneger.aboutme != nil) {
        [parameters setObject:self.maneger.aboutme forKey:@"aboutme"];
    }
    [parameters setObject:@(self.maneger.sex) forKey:@"sex"];
    [parameters setObject:@(self.maneger.height) forKey:@"height"];
    [parameters setObject:@(self.maneger.single) forKey:@"single"];
    if (self.maneger.religion != nil) {
        [parameters setObject:self.maneger.religion forKey:@"religion"];
    }
    //职业
    if (self.maneger.professionsArray.count != 0) {
        NSMutableString *professionsString = [NSMutableString string];
        for (int i=0; i<self.maneger.professionsArray.count; i++) {
            if (i == self.maneger.professionsArray.count - 1) {
                [professionsString appendString:[NSString stringWithFormat:@"%@", self.maneger.professionsArray[i]]];
            } else {
                [professionsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.professionsArray[i]]];
            }
        }
        if (professionsString != nil) {
            [parameters setObject:professionsString forKey:@"professions"];
        }
    }
    //教育
    if (self.maneger.educationsArray.count != 0) {
        NSMutableString *educationsString = [NSMutableString string];
        for (int i=0; i<self.maneger.educationsArray.count; i++) {
            if (i == self.maneger.educationsArray.count - 1) {
                [educationsString appendString:[NSString stringWithFormat:@"%@", self.maneger.educationsArray[i]]];
            } else {
                [educationsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.educationsArray[i]]];
            }
        }
        if (educationsString != nil) {
            [parameters setObject:educationsString forKey:@"educations"];
        }
    }
    //兴趣
    if (self.maneger.interestsArray.count != 0) {
        NSMutableString *interestsString = [NSMutableString string];
        for (int i=0; i<self.maneger.interestsArray.count; i++) {
            if (i == self.maneger.interestsArray.count - 1) {
                [interestsString appendString:[NSString stringWithFormat:@"%@", self.maneger.interestsArray[i]]];
            } else {
                [interestsString appendString:[NSString stringWithFormat:@"%@;", self.maneger.interestsArray[i]]];
            }
        }
        if (interestsString != nil) {
            [parameters setObject:interestsString forKey:@"interests"];
        }
    }
    if (self.maneger.location != nil) {
        [parameters setObject:self.maneger.location forKey:@"location"];
    }
    NSString *lan = [InternationalControl userLanguage];
    if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
        [parameters setObject:@(1) forKey:@"systemLanguage"];
    } else {
        [parameters setObject:@(0) forKey:@"systemLanguage"];
    }
    return parameters;
}

@end
